home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / dev / lang / pcq12src.lzh / Runtime / Readers / ReadCharray.asm < prev    next >
Assembly Source File  |  1990-12-10  |  1KB  |  51 lines

  1.  
  2. *    ReadCharray.asm (of PCQ Pascal runtime library)
  3. *    Copyright (c) 1989 Patrick Quaid
  4.  
  5. *    This reads a character array, one character at a time, from
  6. *    a text file.
  7.  
  8. *    On entry, a0 holds the address of the variable and d3 holds
  9. *    its maximum length.  Characters are read into the buffer until
  10. *    the buffer is full, or a linefeed is read.  In the latter case,
  11. *    the remaining array space is filled with spaces.
  12.  
  13.     SECTION    PCQ_Runtime,CODE
  14.  
  15.     INCLUDE    "/FileRec.i"
  16.  
  17.     XREF    _p%ReadOneChar
  18.     XREF    _p%GetThatChar
  19.     XREF    _p%IOResult
  20.  
  21.     XDEF    _p%ReadCharray
  22. _p%ReadCharray
  23.  
  24.     tst.l    _p%IOResult        ; is IO OK?
  25.     bne    3$
  26.     move.l    a0,a1            ; move buffer address to a1
  27.     move.l    4(sp),a0        ; a0 holds the file record
  28.     move.l    #0,d1            ; d1 holds the current length
  29. 1$    movem.l    a1/d1/d3,-(sp)        ; save buffer, length, max
  30.     jsr    _p%ReadOneChar        ; get the first character
  31.     movem.l    (sp)+,a1/d1/d3        ; restore the registers
  32.     cmp.b    #10,d0            ; was it a linefeed?
  33.     bne    2$            ; if not, keep going
  34.     bra.s    rarfill            ; fill in the rest of array
  35. 2$    move.b    d0,0(a1,d1.l)        ; put the character into buffer
  36.     addq.l    #1,d1            ; advance buffer ptr
  37.     movem.l    a1/d1/d3,-(sp)        ; save regs
  38.     jsr    _p%GetThatChar        ; eat the char
  39.     movem.l    (sp)+,a1/d1/d3        ; restore the regs
  40.     cmp.l    d1,d3            ; are we at max?
  41.     bgt    1$            ; if not, loop
  42. 3$    rts                ; otherwise return
  43. rarfill
  44.     move.b    #' ',0(a1,d1.l)        ; write a space into array
  45.     addq.l    #1,d1            ; advance ptr
  46.     cmp.l    d1,d3            ; are we at the end?
  47.     bgt    rarfill            ; if not, loop
  48.     rts                ; else return
  49.  
  50.     END
  51.